package a01_数组;

/**
 * <p>
 * a02_移除元素
 * </p>
 *
 * @author flyduck
 * @since 2024-06-12
 */
public class a03_移除元素复习3 {

    public static void main(String[] args) {
//        int[] nums = {0,1,2,2,3,0,4,2};
//        int val = 2;
        int[] nums = {3,2,2,3};
        int val = 3;
        int result = removeElement(nums, val);
        System.out.println("result = " + result);
    }


    public static int removeElement(int[] nums, int val) {
        int slowIndex = 0;//将要赋值的元素
        for(int fastIndex = 0;fastIndex < nums.length;fastIndex++){
            if(nums[fastIndex] != val){
                nums[slowIndex] = nums[fastIndex];
                slowIndex++;
            }
        }
        return slowIndex;
    }
}
